package ${package.Controller};

import io.swagger.annotations.*;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import ${package.Service}.${table.serviceName};
import com.generator.utils.*;
import ${package.Entity}.${entity};
import java.util.Map;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
* <p>
* ${table.comment!} 前端控制器
* </p>
* @author ${author}
* @since ${date}
*/
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != ""></#if>/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
    public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
    public class ${table.controllerName} {
    </#if>
    @Autowired
    private ${table.serviceName} service;


    @Operation(summary = "分页列表")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "currentPage", value = "当前页码", paramType = "query", dataType = "int"),
    @ApiImplicitParam(name = "pageSize", value = "每页显示个数", paramType = "query", dataType = "int")
    })
    @GetMapping(value = "/page")
    public Result page(@RequestParam Map<String, Object> params) {
        PageData<${entity}> page = service.Page(params);
        //返回结果集
        return new Result().ok(page);
    }

    /**
    * 添加信息
    */
    @PostMapping("add")
    @Operation(summary = "添加信息")
    public Result add(@RequestBody ${entity} entity) {
        int n = service.add(entity);
        if (n > 0) {
            return new Result().ok();
        } else {
            return new Result().err(400, "添加失败");
        }
    }

    /**
    * 编辑信息
    */
    @PutMapping("update")
    @Operation(summary = "修改信息")
    public Result update(@RequestBody ${entity} entity) {
        int n = service.update(entity);
        if (n > 0) {
            return new Result().ok();
        } else {
            return new Result().err(400, "编辑失败");
        }
    }


    /**
    * 根据ids删除信息
    */
    @DeleteMapping("/{id}")
    @Operation(summary = "根据ids删除信息")
    public Result del(@PathVariable("id") Long id){
        int n = service.delete(id);
        if (n > 0) {
            return new Result().ok();
        } else {
            return new Result().err(400, "删除失败");
        }
    }
}
</#if>
